package com.project.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.dtyunxi.rest.RestResponse;
import com.google.common.collect.Lists;
import com.project.entity.area.Area;
import com.project.service.IAreaService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("api/area")
@Api(value = "api/area", description = "区域管理")
public class AreaController {
	
	@Autowired
	private IAreaService areaService;
	
	@RequestMapping(value = "/ops", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "获取区域信息", httpMethod = "GET", response = Area.class, notes = "获取区域信息")
	public RestResponse getAreaList(
			@ApiParam(required = false, name = "code",value="父编码，获取省时不传参数") @RequestParam(required = false, value = "code") String code) {
		List<Area> list = Lists.newArrayList();
		if(StringUtils.isBlank(code)) {
			list = areaService.getProvinceList();
		}else{
			list = areaService.getChildList(code);
		}

		return new RestResponse(list);
	}
	
	

}
